//
//  LRButton.m
//  ZCLButton
//
//  Created by 徐益智 on 16/3/12.
//  Copyright © 2016年 Vdianjing. All rights reserved.
//

#import "LRButton.h"

#import "VDJConstant.h"

@implementation LRButton


- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    
    CGFloat w = self.frame.size.width;
    CGFloat h = self.frame.size.height;
    CGFloat x = w - self.imageWidth - 2;
    CGFloat margin = (h - self.imageWidth) / 2.0;
    
    
    if (self.style == LRButtonStyleRImageLText) {
        return CGRectMake(2, margin, self.imageWidth, self.imageWidth);
    }
    
    if (self.style == LRButtonStyleRTextLImage) {
        return CGRectMake(x, margin, self.imageWidth, self.imageWidth);
    }
    
    return CGRectZero;
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    
    CGFloat w = self.frame.size.width;
    CGFloat h = self.frame.size.height;
//    CGFloat x = w - self.imageWidth - 2;
//    CGFloat margin = (h - self.imageWidth) / 2.0;
    
    
    if (self.style == LRButtonStyleRImageLText) {
        return CGRectMake(kGetX(self.imageView.frame) + 2, 2, w - 6 - self.imageWidth, h - 4);
    }
    
    if (self.style == LRButtonStyleRTextLImage) {
        return CGRectMake(2, 2, w - 6 - self.imageWidth, h - 4);
    }
    return CGRectZero;
}


//- (void)layoutSubviews
//{
//    if (self.style == LRButtonStyleRImageLText) {
//        CGFloat w = self.frame.size.width;
//        CGFloat h = self.frame.size.height;
//        
//        CGFloat margin = (h - self.imageWidth) / 2.0;
//        
//        self.imageView.frame = CGRectMake(2, margin, self.imageWidth, self.imageWidth);
//        
//        self.titleLabel.textAlignment = NSTextAlignmentCenter;
//        self.titleLabel.frame = CGRectMake(kGetX(self.imageView.frame) + 2, 2, w - 6 - self.imageWidth, h - 4);
//        
//        
//        self.titleLabel.backgroundColor = [UIColor blueColor];
//        self.imageView.backgroundColor = [UIColor yellowColor];
//    }
//    
//    if (self.style == LRButtonStyleRTextLImage) {
//        CGFloat w = self.frame.size.width;
//        CGFloat h = self.frame.size.height;
//        
//        CGFloat x = w - self.imageWidth - 2;
//        
//        CGFloat margin = (h - self.imageWidth) / 2.0;
//        
//        self.imageView.frame = CGRectMake(x, margin, self.imageWidth, self.imageWidth);
//        
//        self.titleLabel.textAlignment = NSTextAlignmentCenter;
//        self.titleLabel.frame = CGRectMake(2, 2, w - 6 - self.imageWidth, h - 4);
//        
//        
//        self.titleLabel.backgroundColor = [UIColor blueColor];
//        self.imageView.backgroundColor = [UIColor yellowColor];
//    }
//    
//}

@end
